﻿using AutoMapper;
using DFGK.IRepository;
using DFGK.IService;
using DFGK_WMS.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace DFGK.Service
{
    public class InterfaceLogService : BaseService, IInterfaceLogService
    {
        private readonly IInterfaceLogRepository _interfaceLogRepository;
        private readonly IUnitOfWork _unitOfWork;
        public InterfaceLogService(IMapper mapper, IInterfaceLogRepository _interfaceLogRepository, IUnitOfWork _unitOfWork) : base(mapper)
        {
            this._interfaceLogRepository = _interfaceLogRepository;
            this._unitOfWork = _unitOfWork;
        }

        public bool AddInterfaceLog(InterfaceLog m, out string message)
        {
            message = string.Empty;
            _interfaceLogRepository.AddEntity(m);
            return _unitOfWork.SaveChangesEntity();
        }

        public List<InterfaceLog> GetInterfaceLogList(int? status, int pageIndex, int pageSize, out int totalCount)
        {
            var alist = _interfaceLogRepository.GetEntityAlls();

            if (status != null)
            {
                alist = alist.Where(x => x.Status == status);
            }
            
            var list = _interfaceLogRepository.GetEntityAlls(alist, pageIndex, pageSize, out totalCount, x => x.CreateDate, false);
            return list.ToList();
        }
    }
}
